package spill;

import java.awt.Graphics;
import java.awt.Graphics2D;

public class Hand extends Item {
	private int startY = 100;
	private int endY = 500;
	private char text[] = {'a', 'b', 'a', 'k', 'u', 's'};
	private int step = 10;
	private boolean inUse = false;
	private boolean goingDown = true;
	private boolean hit;
	private Student student;
	public Hand(Engine en, Student student) {
		super("Graphics/HandC.txt", "Graphics/HandD.txt", en);
		this.student = student;
	}
	
	public void strike(int x) {
		if (!inUse) {
			this.x = x-30;
			inUse = true;
			goingDown = true;
			y = startY;
			hit = false;
		}
	}
	
	public void draw(Graphics g) {
		if (inUse) {
			if (goingDown && y < endY) {
				y += step;
			}
			else if (goingDown) {
				goingDown = false;
				if (student.getX() > x && student.getX() < x+40) {
					hit = true;
					engine.remove(student);
				}
			}
			else if (y > startY) {
				y -= step;
			}
			else {
				inUse = false;
				if (hit) {
					engine.makeItRain();
					student.setInUse(false);
				}
			}
			g.setColor(getColor('s'));
			for (int i = startY; i < y; i+=step) {//draw arm
				g.drawString(text[(i/step)%text.length]+"  "+text[(i/step)%text.length], x+20, i);
			}
			if (hit) {//draw student
				Graphics2D g2d = (Graphics2D) g.create();
				g2d.rotate(Math.PI/4, x, y);
				student.setCoord(x, y);
				student.draw(g2d);
				g2d.dispose();
			}
			super.draw(g);
		}
	}
}
